$category = $this->get_primary_category_label( $post->ID ); $description = $this->build_recipe_description( $post, $schema_data ); return array( 'title' => get_the_title( $post->ID ), 'description' => $description, 'ingredients' => $ingredients, 'instructions' => $instructions, 'prep_time' => $prep_time, 'cook_time' => $cook_time, 'total_time' => $this->build_total_time_label( $prep_time, $cook_time ), 'servings' => $servings, 'nutrition' => $nutrition, 'category' => $category, 'notes' => $notes, 'image' => get_the_post_thumbnail_url( $post->ID, 'full' ) ?: '', 'url' => get_permalink( $post->ID ), $category = $this->get_primary_category_label( $post->ID ); $description = $this->build_recipe_description( $post, $schema_data ); return array( 'title' => get_the_title( $post->ID ), 'description' => $description, 'ingredients' => $ingredients, 'instructions' => $instructions, 'prep_time' => $prep_time, 'cook_time' => $cook_time, 'total_time' => $this->build_total_time_label( $prep_time, $cook_time ), 'servings' => $servings, 'nutrition' => $nutrition, 'category' => $category, 'notes' => $notes, 'image' => get_the_post_thumbnail_url( $post->ID, 'full' ) ?: '', 'url' => get_permalink( $post->ID ), ); } $ingredients = ! empty( $schema_data['ingredients'] ) ? (array) $schema_data['ingredients'] : $this->extract_html_list_section( $content, array( 'Ingredients', 'Ingredient', 'What You Need', 'المكونات' ) ); if ( empty( $ingredients ) ) { $ingredients = $this->extract_list_block( $plain, array( 'Ingredients', 'Ingredient', 'المكونات' ), array( 'Instructions', 'Directions', 'Method', 'طريقة التحضير', 'الطريقة', 'Prep Time', 'Cook Time', 'Nutrition', 'FAQ', 'الأسئلة الشائعة' ) ); } $instructions = ! empty( $schema_data['instructions'] ) ? (array) $schema_data['instructions'] : $this->extract_html_list_section( $content, array( 'Instructions', 'Directions', 'Method', 'How to Make', 'طريقة التحضير', 'الطريقة' ) ); if ( empty( $instructions ) ) { $instructions = $this->extract_list_block( $plain, array( 'Instructions', 'Directions', 'Method', 'طريقة التحضير', 'الطريقة' ), array( 'Nutrition', 'Prep Time', 'Cook Time', 'Ingredients', 'FAQ', 'الأسئلة الشائعة' ) ); } $prep_time = ! empty( $schema_data['prep_time'] ) ? (string) $schema_data['prep_time'] : $this->extract_inline_value( $plain, array( 'Prep Time', 'وقت التحضير' ) ); $cook_time = ! empty( $schema_data['cook_time'] ) ? (string) $schema_data['cook_time'] : $this->extract_inline_value( $plain, array( 'Cook Time', 'وقت الطهي', 'وقت الطبخ' ) ); $nutrition = ! empty( $schema_data['nutrition'] ) ? (string) $schema_data['nutrition'] : $this->extract_inline_value( $plain, array( 'Nutrition', 'القيم الغذائية' ) ); $servings = ! empty( $schema_data['servings'] ) ? (string) $schema_data['servings'] : $this->extract_inline_value( $plain, array( 'Servings', 'Yield', 'الكمية', 'عدد الحصص' ) ); $notes = $this->extract_html_notes_section( $content, array( 'Notes', 'Tips', 'Chef Tips', 'Storage', 'ملاحظات', 'نصائح', 'التخزين' ) ); $category = $this->get_primary_category_label( $post->ID ); private function build_recipe_card_html( WP_Post $post, array $data ): string { $schema = array( '@context' => 'https://schema.org', '@type' => 'Recipe', 'name' => (string) $data['title'], 'description' => (string) $data['description'], 'keywords' => implode( ', ', $this->build_recipe_keywords( $post, $data ) ), 'mainEntityOfPage' => (string) $data['url'], 'recipeIngredient' => array_values( (array) $data['ingredients'] ), 'recipeInstructions' => array(), ); if ( ! empty( $data['image'] ) ) { $schema['image'] = array( (string) $data['image'] ); } if ( ! empty( $data['prep_time'] ) ) { $schema['prepTime'] = $this->label_to_iso_duration( (string) $data['prep_time'] ); } if ( ! empty( $data['cook_time'] ) ) { $schema['cookTime'] = $this->label_to_iso_duration( (string) $data['cook_time'] ); } if ( ! empty( $data['total_time'] ) ) { $schema['totalTime'] = $this->label_to_iso_duration( (string) $data['total_time'] ); } if ( ! empty( $data['servings'] ) ) { $schema['recipeYield'] = (string) $data['servings']; } if ( ! empty( $data['nutrition'] ) ) { $schema['nutrition'] = array( '@type' => 'NutritionInformation', 'calories' => (string) $data['nutrition'], ); } $aggregate_rating = $this->build_recipe_aggregate_rating( $post ); if ( ! empty( $aggregate_rating ) ) { $schema['aggregateRating'] = $aggregate_rating; } $video = $this->build_recipe_video_object( $post, $data ); if ( ! empty( $video ) ) { $schema['video'] = $video; } foreach ( (array) $data['instructions'] as $step ) { $schema['recipeInstructions'][] = array( '@type' => 'HowToStep', 'text' => (string) $step, ); } $html = self::CARD_START . "\n"; $html .= '
' . esc_html( (string) $data['description'] ) . '
'; } $rating_value = ''; $review_count = 0; if ( ! empty( $schema['aggregateRating'] ) && is_array( $schema['aggregateRating'] ) ) { $rating_value = isset( $schema['aggregateRating']['ratingValue'] ) ? (string) $schema['aggregateRating']['ratingValue'] : ''; $review_count = isset( $schema['aggregateRating']['reviewCount'] ) ? (int) $schema['aggregateRating']['reviewCount'] : 0; } $html .= '